
// 写上数据

const data = [
    {
        "goodsId": "A001",
        "goodsName": "华为 HUAWEI P40 Pro",
        "goodsMsg": "华为 HUAWEI P40 Pro 麒麟990 5G SoC芯片 5000万超感知徕卡四摄 50倍数字变焦 8GB+128GB冰霜银全网通5G",
        "goodsImg": "https://img12.360buyimg.com/n7/jfs/t1/139098/11/697/82375/5ee6fcebE11053e13/f5df8e27a0b546c5.jpg",
        "goodsPrice": 5988
    },
    {
        "goodsId": "A002",
        "goodsName": "Apple iPhone 11",
        "goodsMsg": "Apple iPhone 11 (A2223) 128GB 黑色 移动联通电信4G",
        "goodsImg": "https://img10.360buyimg.com/n7/jfs/t1/41566/13/14792/149059/5d7809a7E99b4ed1b/56ea66c5f8a6f724.jpg",
        "goodsPrice": 5999
    },
    {
        "goodsId": "A003",
        "goodsName": "一加8Pro OnePlus",
        "goodsMsg": "一加8Pro OnePlus 1+8Pro 5G手机2K+120Hz 青空色",
        "goodsImg": "https://img13.360buyimg.com/n7/jfs/t1/131844/26/2030/179283/5ee212b8E6037a065/8ebdf06de22e64e0.jpg",
        "goodsPrice": 5399
    },
    {
        "goodsId": "A003",
        "goodsName": "小米10pro",
        "goodsMsg": "小米10pro 双模5G游戏手机【至高12期分期0首付】 珍珠白 12G+256G",
        "goodsImg": "https://img12.360buyimg.com/n7/jfs/t1/130507/6/2419/623986/5eea0995E7333f0e8/7ebbebf5a6312e30.png",
        "goodsPrice": 4928
    }
]





// 商品列表处理函数
const listHandle = (req, res) => {

    res.send({ s: true, msg: '商品列表接口测试', data })
}


// 商品详情处理函数
const detailHandle = (req, res) => {

    // 接收前端传来的id
    const { id } = req.query;

    if (id) {
        const result = data.find(item => item.goodsId === id);

        res.send({ s: true, msg: '商品列表接口测试', data: result })
    }
    else {


        res.send({ s: 0, msg: '参数错误' })
    }


}





module.exports.listHandle = listHandle;

module.exports.detailHandle = detailHandle;